<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
include 'header.php';
include 'menu.php';
?>


</head>
<body>
<br><br><br>
<?php 

//Get config file
$configfile='/etc/opt/fbc/fbc.xml';
$type=$_GET['type'];

if ($type == "domain")
	$typetext = "Domain";
if ($type == "po")
	$typetext = "Post Office";

//Placing either 'New Domain' or 'New Post Office' based on which new server they're going to add.
 echo "<b>New $typetext</b><hr><br>";

?>


<form name="form1" method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
<table>

<tr><td><b>Name: </b></td>
<td><input type="text" name="name" /></td></tr>
<tr><td><b>IP Address: </b></td>
<td> <input type="text" name="ipaddr" /></td></tr>
<tr><td><b>Remote Path: </b></td>
<td><input type="text" name="remotepath" /></td></tr>
<tr><td><b>Remote User: </b></td>
<td><input type="text" name="remoteuser" /></td></tr>
<tr><td><b>Remote Password: </b></td>
<td><input type="password" name="remotepass" /></td></tr>
<tr><td><b>Mount Type: </b></td>
<td>Samba<input type='radio' value='Samba' name='mounttype'
    <?php if ($settings[mounttype] == "samba" or $settings[mounttype] == "Samba") echo 'checked';?> >
    NCP<input type='radio' value='NCP' name='mounttype'
    <?php if ($settings[mounttype] == "NCP") echo 'checked';?> ></td></tr>
		 
<?php
if($type == 'domain')
{
	echo "</table>";
	echo "<input name='type' type='hidden' value='domain' />";
}
if($type == 'po')
{
	echo "<tr><td>Domain: </td>";
	echo "<td><input name='domain' type='text' /></td></tr>";
	echo "</table>";
	echo "<input name='type' type='hidden' value='po' />";
}
?>
<br>
<input type="submit" name="submit" value="Add <?php echo $typetext;?>" />
</form>
<br>
<?php
   if(isset($_POST['submit']))
    {
    //Collecting Variables while cancelling out variables received from XML file (this whole section should only happen if the user clicked Save.


        $xml = simplexml_load_file($configfile);

        $name = $_POST['name'];
        $ipaddr = $_POST['ipaddr'];
        $remotepath = $_POST['remotepath'];
        $remoteuser = $_POST['remoteuser'];
        $remotepass = $_POST['remotepass'];
        $mounttype = $_POST['mounttype'];
        $type = $_POST['type'];
        $domain = $_POST['domain'];

        //Create array of xml tags with data

        $newserver['type'] = $type;
        $newserver['ipaddr'] = $ipaddr;
        $newserver['name'] = $name;
        $newserver['remotepath'] = $remotepath;
        $newserver['remoteuser'] = $remoteuser;
        $newserver['remotepass'] = $remotepass;
        $newserver['mounttype'] = $mounttype;
        $newserver['basepath'] = '';
        $newserver['currentfulldate'] = '';
        $newserver['currentfullpath'] = '';
        $newserver['restorepath'] = '';
        $newserver['starttime'] = '';
        $newserver['endtime'] = '';

        if ($type == 'po')
        {
            $newserver['domain'] = $domain;
            $newserver['currentinc'] = '';
            $newserver['inc1date'] = '';
            $newserver['inc2date'] = '';
            $newserver['inc3date'] = '';
            $newserver['inc4date'] = '';
            $newserver['inc5date'] = '';
            $newserver['inc6date'] = '';
            $newserver['oldfullpath'] = '';
        }

     	$server = $xml->addChild('server');
        foreach ($newserver as $key=>$value)
        {
            $server->addChild($key, $value);
        }
		$dom = new DOMDocument(1.0);
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($xml->asXML());
        $dom->save($configfile);
		header("Location:index.php");
    }

?>

</html>
<?php include 'footer.php'; ?>
